/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.netbeans.modules.php.project.environment;

import java.io.File;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.openide.util.NbBundle;

/**
 * @author Tomas Mysik
 */
final class MacPhpEnvironment extends PhpEnvironment {

    private static final String PHP = "php"; // NOI18N
    private static final PhpEnvironment MAMP = new MampPhpEnvironment();


    MacPhpEnvironment() {
    }

    @Override
    protected List<DocumentRoot> getDocumentRoots(String projectName) {
        return MAMP.getDocumentRoots(projectName);
    }

    @Override
    public List<String> getAllPhpInterpreters() {
        List<String> phps = new LinkedList<>();
        // system path
        phps.addAll(getAllPhpInterpreters(PHP));
        // mamp
        phps.addAll(MAMP.getAllPhpInterpreters());
        return phps;
    }

    //~ Inner classes

    /**
     * {@link PhpEnvironment} implementation for MAMP.
     */
    @org.netbeans.api.annotations.common.SuppressWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
    private static final class MampPhpEnvironment extends PhpEnvironment {

        @Override
        protected List<DocumentRoot> getDocumentRoots(String projectName) {
            File mamp = new File("/Applications/MAMP/htdocs"); // NOI18N
            if (mamp.isDirectory()) {
                String documentRoot = getFolderName(mamp, projectName);
                String url = getDefaultUrl(projectName, 8888);
                String hint = NbBundle.getMessage(MampPhpEnvironment.class, "TXT_MampHtDocs");
                return Collections.singletonList(new DocumentRoot(documentRoot, url, hint, true));
            }
            return Collections.emptyList();
        }

        @Override
        public List<String> getAllPhpInterpreters() {
            File php = new File("/Applications/MAMP/bin/php5/bin/php"); // NOI18N
            if (php.isFile()) {
                return Collections.singletonList(php.getAbsolutePath());
            }
            return Collections.emptyList();
        }

    }

}
